<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>

<style>
	.select-box{width:110px;float:left;}
</style>

<?php 
	$segment = $this->uri->segment(2,'');
	$fixedVar = false;
	if($segment){
		$linkArr = reDirectSite();
		if( in_array($segment,array_keys($linkArr)) ){
			$fixedVar = true;
		}
	}
	
	$escortAgeRange = getEscortAgeRange();
	$minAge = 18;
	$maxAge = convertAgeFromTimeStamp($escortAgeRange['max_age']);
	
	$breastSizeRange = getBreastSizeRange();
	$min_size = $breastSizeRange['min_size'];
	$max_size = $breastSizeRange['max_size'];
	
	$priceRange = getPriceRange();
	$min_price = $priceRange['min_price'];
	$max_price = $priceRange['max_price'];
	
	$hairColorArray = getHairColorOptionData_ioc();
	$servicesDataArray = getServicesData_ioc();
	$languageArray = getLanguagesOfEscortsUsed();
	$measureOptionArray = getMeasureOptionData_ioc();
	$professionArray = getProfessionData_ioc();
	
	$listPackArray = array();
	foreach(getPackListData_ioc() as $key=>$arrayValue){
		$listPackArray[$key] = $arrayValue[0];
	}
	 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	$pre = array_keys(getCountriesOfEscortsUsed());
	$DEFAULT_COUNTRY = getCountryInfoFromUserGeoLocation();
	$preCountry = ($DEFAULT_COUNTRY) ? $DEFAULT_COUNTRY->getId() : $pre[0];
	$cityData = getCityInfoFromUserGeoLocation();
		
	$category_id = (isset($_GET['category_id'])) ? intval($_GET['category_id']) : null;
	$country_id = (isset($_GET['country_id'])) ? intval($_GET['country_id']) : $preCountry;
	$state_id = (isset($_GET['state_id'])) ? intval($_GET['state_id']) : $cityData['state_id'];
	$province_id = (isset($_GET['province_id'])) ? intval($_GET['province_id']) : 0;
	$city_id = (isset($_GET['city_id'])) ? intval($_GET['city_id']) : $cityData['city_id'];
	$state_province_city_id = (isset($_GET['state_province_city_id'])) ? $_GET['state_province_city_id'] : 'na';
	if($state_province_city_id != 'na'){
		$epl = explode('|',$state_province_city_id);
		$state_id = isset($epl[0]) ? $epl[0]:0;
		$province_id = isset($epl[1]) ? $epl[1]:0;
		$city_id = isset($epl[2]) ? $epl[2]:0;
	}
	if($fixedVar){
		$country_id = $linkArr[$segment]['country_id'];
		$state_id = $linkArr[$segment]['state_id'];
		$province_id = $linkArr[$segment]['province_id'];
		$city_id = $linkArr[$segment]['city_id'];
	}
	
	$name = $this->input->get('name', '');
	
	$categoryForm = form_dropdown('category_id', getEscortCategoryData_ioc(), array($category_id) , 'id="category_id" class="custom"' );
	$countryForm = form_dropdown('country_id', getCountriesOfEscortsUsed(), array($country_id) , 'id="country_id" class="custom"' );
	//$stateForm = form_dropdown('state_id', getStateData_ioc($country_id), array($state_id) , 'id="state_id" class="custom"' );
	$stateForm = $this->home_m->changeCountry_async($country_id);
	$provinceForm = form_dropdown('province_id', getProvinceData_ioc($country_id,$state_id), array($province_id) , 'id="province_id" class="custom"' );
	$cityForm = form_dropdown('city_id', getCityData_ioc($country_id, $state_id, $province_id), array($city_id) , 'id="city_id" class="custom"' );
	
	//$mediaFormArray = isset($_GET['media']) ? array_filter($_GET['media']): array();//array_keys($listPackArray);
	$agentFormArray = isset($_GET['agent']) ? array_filter($_GET['agent']):array();
	$hairFormArray = isset($_GET['hair_id']) ? array_filter($_GET['hair_id']): array();//array_keys($hairColorArray);
	$servicesFormArray = isset($_GET['services']) ? array_filter($_GET['services']): array(); //array_keys($servicesDataArray);
	$languagesFormArray = isset($_GET['language']) ? array_filter($_GET['language']): array() ;//array_keys($languageArray);
	$professionFormArray = isset($_GET['profession']) ? array_filter($_GET['profession']): array() ;
	
	$from_age = isset($_GET['from_age']) ? intval($_GET['from_age']) : $minAge;
	$to_age = isset($_GET['to_age']) ? intval($_GET['to_age']) :$maxAge;
	
	$from_price = isset($_GET['from_price']) ? intval($_GET['from_price']) : $min_price;
	$to_price = isset($_GET['to_price']) ? intval($_GET['to_price']) : $max_price;
	
	$from_size = isset($_GET['from_size']) ? intval($_GET['from_size']) : $min_size;
	$to_size = isset($_GET['to_size']) ? intval($_GET['to_size']) : $max_size;
	
	$without_price = isset($_GET['without_price']) ? intval($_GET['without_price']) : 1;
	
	$agent_id = 0;
	if(isset($_GET['tm']) AND $_GET['tm'] == 'ag'){
		$agent_id = intval($_GET['uid']);
		$agentFormArray[] = 1;
	}	
?>



<div class="search-left">
	<span class="search-result"><?php echo language_translate('search_escort_search_result');?><span id="search_result_show_id"></span></span>
	<form action="{{url:base}}home/search" id="search_form">
		<div class="search-indicator">
			<a href="<?php echo site_url_lang("home/search/?df=1");?>"><?php echo language_translate('search_escort_reset_search');?></a>
		</div>
		
		<div class="search-indicator">
			<span class="search-item-title"><?php echo language_translate('plugin_sys_name');?></span>
			<input type="text" id="escort-data" name="name" value="<?php echo $name;?>" />
		</div>
		
		<div class="search-indicator" style="position:relative;">
			<span class="search-item-title"><?php echo language_translate('search_escort_location');?></span>
			<div class="toggleSection collapse" rel="location_id"></div>
			<div id="location_id">
				<?php echo $countryForm;?>
				<div class="clear"></div>
				<div>
					<div class="select-box" id="slb_state_id">
						<?php echo $stateForm;?>
					</div>
					<?php echo loader_image_s('id="slb_state_id_loader" class="hidden"'); ?>
				</div>
				<div class="clear"></div>
			<!--	
				<div>
					<div class="select-box" id="slb_province_id" >
						<?php //echo $provinceForm;?>
					</div>
					<?php //echo loader_image_s('id="slb_province_id_loader" class="hidden"'); ?>
				</div>
				<div class="clear"></div>
				<div>
					<div class="select-box" id="slb_city_id" >
						<?php //echo $cityForm;?>
					</div>
					<?php //echo loader_image_s('id="slb_city_id_loader" class="hidden"'); ?>
				</div>
			-->	
			</div>
		</div>
		
	<!-- 	
		<div class="search-indicator">
			<span class="search-item-title"><?php //echo language_translate('search_escort_media');?></span>
			<?php //foreach($listPackArray as $k=>$item):?>
				<div class="checkbox-wrapper">
					<input class="custom" type="checkbox" value="<?php //echo $k;?>" name="media[]" <?php //echo (in_array($k,$mediaFormArray)) ? 'checked="checked"':'';?>/> 
					<label for="certified-photos"><?php //echo $item;?></label>
				</div>
			<?php //endforeach;?>
		</div>
	 -->
	 	
		<div class="search-indicator">
			<span class="search-item-title"><?php echo language_translate('search_escort_agency');?></span>
			<div class="checkbox-wrapper"><input class="custom" type="checkbox" value="0" name="agent[]" <?php echo (in_array(0,$agentFormArray)) ? 'checked="checked"':'';?>/> <label>Independent</label></div>
			<div class="checkbox-wrapper"><input class="custom" type="checkbox" value="1" id="agentIDCheckedItem" name="agent[]" <?php echo (in_array(1,$agentFormArray)) ? 'checked="checked"':'';?>/> <label>Agency</label></div>
			
			<?php 
				if($agent_id != 0){
					$clscss = "wrapAGENT";
				}else{
					$clscss = "wrapAGENT hidden";
				}
			?>
			<div class="<?php echo $clscss;?>">
				<div class="clear" style="height:5px;"></div>
				<?php echo form_dropdown("agency_id",getAgencyListData_ioc(),array($agent_id),"id='agency_id' class='custom' ");?>
			</div>	
		</div>
		
		<div class="search-indicator">
			<span class="search-item-title"><?php echo language_translate('search_escort_hair_color');?></span>
			<?php foreach($hairColorArray as $key=> $hair):?>
				<div class="checkbox-wrapper">
					<input class="custom" type="checkbox" value="<?php echo $key;?>" name="hair_id[]" <?php echo (in_array($key,$hairFormArray)) ? 'checked="checked"':'';?> /> 
					<label><?php echo $hair;?></label>
				</div>
			<?php endforeach;?>
		</div>
		
		<div class="search-indicator">
			<input type="hidden" name="from_age" id="from_age" value="<?php echo $from_age;?>" />
			<input type="hidden" name="to_age" id="to_age" value="<?php echo $to_age;?>" />
			<span class="search-item-title" style="margin-bottom:25px;"><?php echo language_translate('search_escort_age');?></span>
			<span id="from_age_slide_show"><?php echo $from_age;?></span>
			<span id="to_age_slide_show"><?php echo $to_age;?></span>
			<div id="slider-age" class="slider-horizontal"></div>
		</div>
		
		<div class="search-indicator">
			<input type="hidden" name="from_price" id="from_price" value="<?php echo $from_price;?>" />
			<input type="hidden" name="to_price" id="to_price" value="<?php echo $to_price;?>" />
			<span class="search-item-title" style="margin-bottom:25px;"><?php echo language_translate('search_escort_price');?>/&euro;</span>
			<span id="from_price_slide_show"><?php echo $from_price;?> </span>
			<span id="to_price_slide_show"><?php echo $to_price;?> </span>
			<div id="slider-price" class="slider-horizontal"></div>
			<div class="checkbox-wrapper">
				<input class="custom" type="checkbox" value="1" name="without_price" id="without_price" <?php echo ($without_price == 1) ? 'checked="checked"':'';?> /> 
				<label><?php echo language_translate('search_escort_non_price');?></label>
			</div>
		</div>
		
		<div class="search-indicator">
			<input type="hidden" name="from_size" id="from_size" value="<?php echo $from_size;?>" />
			<input type="hidden" name="to_size" id="to_size" value="<?php echo $to_size;?>" />
			<span class="search-item-title" style="margin-bottom:25px;"><?php echo language_translate('search_escort_breast_size');?>/Cm</span>
			<span id="from_breasts_size_slide_show"><?php echo $from_size;?></span> 
			<span id="to_breasts_size_slide_show"><?php echo $to_size;?></span> 
			<div id="slider-size-breast" class="slider-horizontal"></div>
		</div>
		
		<!--	
		<div class="search-indicator">
			<input type="hidden" name="penis_size" id="penis_size" value="<?php //echo $penis_size;?>" />
			<span class="search-item-title">Penis size</span>
			<span id="penis_size_slide_show"><?php //echo $penis_size;?></span> Cm
			<div id="slider-size-penis" class="slider-horizontal"></div>
		</div>	
		-->
		
		<div class="search-indicator" style="position:relative;">
			<span class="search-item-title"><?php echo language_translate('search_escort_services');?></span>
			<div class="toggleSection expand" rel="services_id"></div>
			<div id="services_id" class="hidden">
				<?php foreach($servicesDataArray as $key=> $service):?>
					<div class="checkbox-wrapper">
						<input class="custom" type="checkbox" value="<?php echo $key;?>" name="services[]" <?php echo (in_array($key,$servicesFormArray)) ? 'checked="checked"':'';?> /> 
						<label><?php echo $service;?></label>
					</div>
				<?php endforeach;?>
			</div>
		</div>
		
		<div class="search-indicator" style="position:relative;">
			<span class="search-item-title"><?php echo language_translate('search_escort_profession');?></span>
			<div class="toggleSection expand" rel="profession_id"></div>
			<div id="profession_id" class="hidden">
				<?php foreach($professionArray as $key=> $profession):?>
					<div class="checkbox-wrapper">
						<input class="custom" type="checkbox" value="<?php echo $key;?>" name="profession[]" <?php echo (in_array($key,$professionFormArray)) ? 'checked="checked"':'';?> /> 
						<label><?php echo $profession;?></label>
					</div>
				<?php endforeach;?>
			</div>
		</div>
		
		<div class="search-indicator" style="position:relative;">
			<span class="search-item-title"><?php echo language_translate('borncountry_label');?></span>
			<div class="toggleSection expand" rel="borncountryS_id" onclick="javascript:$('#borncountry_id').height(20);"></div>
			<div id="borncountryS_id" class="hidden">
				<?php echo form_dropdown("borncountry_id",getBornCountryData_ioc(),array(),"id='borncountry_id' class='custom' ");?>
			</div>
		</div>
		
		<div class="search-indicator" style="position:relative;">
			<span class="search-item-title"><?php echo language_translate('search_escort_language');?></span>
			<div class="toggleSection expand" rel="languages_id"></div>
			<div id="languages_id" class="hidden">
				<?php foreach($languageArray as $id=> $language): ?>
					<div class="checkbox-wrapper">
						<input class="custom" type="checkbox" value="<?php echo $id;?>" name="language[]" <?php echo (in_array($id,$languagesFormArray)) ? 'checked="checked"':'';?> /> 
						<label><?php echo $language;?></label>
					</div>
				<?php endforeach;?>
			</div>	
		</div>
		
		<div class="search-submit-wrapper">
			<input type="submit" class="search-submit" name="search" value="<?php echo language_translate('search_escort_search_label');?>" />
		</div>
		
	</form>
	<div class='greyDiv hidden'></div>
</div>

<div id="search-escort">
	<?php $this->load->view('home/search_escort'); ?>
</div>

<div class="bottom-content-wrapper">
	<?php $this->load->view('banner/bottom_banner',array('pos'=>'search') ); ?>
</div>

<?php 
	$stringDesc = '';
	$location = $this->home_m->findLocationInfo();
	$sLoc = ($location['city'])?$location['city']:( ($location['province'])?$location['province']:(($location['state'])?:$location['country']));
	if($sLoc){
		$stringDesc = str_replace('$1',$sLoc,language_translate('search_escort_location_desc')); 
	}elseif(isset($_GET['tm']) AND $_GET['tm'] == 'ag'){
		$user_id = intval($_GET['uid']);
		$U = $this->user_entity->init('id',$user_id);
		$stringDesc = str_replace('$1',$U->getName(),language_translate('search_escort_of_agent_desc')); 
		
		//change breadcumb
		breadcumb_reset();
		breadcumb(2,array(language_translate('breadcumb_search'), site_url_lang("home/search")));	
		breadcumb(3,array(language_translate('breadcumb_agent'), site_url_lang("home/search")));
		breadcumb(4,array($U->getName(), site_url_lang("home/search/?tm=ag&uid=$user_id")));
		echo breadcumb_html();
	}	
	 
?>

<?php if($stringDesc):?>
	<script type="text/javascript">
		$(document).ready(function(){
			var desc = '<?php echo $stringDesc;?>';
			$('#search-desc').show().html(desc);
		});
	</script>
<?php endif;?>

<script type="text/javascript">
	function loadDynamicJSResult(){
		//slider
		$( "#slider-age").slider({
			//orientation: "horizontal",
			range: true,
			min: <?php echo $minAge;?>,
			max: <?php echo $maxAge;?>,
			values: [$( "#from_age" ).attr('value'), $( "#to_age" ).attr('value')],
			slide: function( event, ui ) {
				$( "#from_age" ).attr('value', ui.values[0]);
				$( "#to_age" ).attr('value', ui.values[1]);
				$( "#from_age_slide_show" ).html(ui.values[0]);
				$( "#to_age_slide_show" ).html(ui.values[1]);
			},
			stop: function(event, ui) {async_search();return false; }
		});
		$( "#slider-price").slider({
			//orientation: "horizontal",
			range: true,
			min: <?php echo $min_price;?>,
			max: <?php echo $max_price;?>,
			values: [$( "#from_price" ).attr( 'value' ), $( "#to_price" ).attr( 'value' )],
			slide: function( event, ui ) {
				$( "#from_price" ).attr( 'value', ui.values[0] );
				$( "#to_price" ).attr( 'value', ui.values[1] );
				$( "#from_price_slide_show" ).html(ui.values[0]+ ' &euro;');
				$( "#to_price_slide_show" ).html(ui.values[1]+ ' &euro;');
			},
			stop: function(event, ui) {
				if($('#without_price').prop("checked")){
					$('#without_price').prop("checked",false);	
				}
				async_search();
				return false; 
			}
		});
		$( "#slider-size-breast").slider({
			//orientation: "horizontal",
			range: true,
			min: <?php echo $min_size;?>,
			max: <?php echo $max_size;?>,
			values: [ $( "#from_size" ).attr( 'value' ), $( "#to_size" ).attr( 'value' )],
			slide: function( event, ui ) {
				$( "#from_size" ).attr( 'value', ui.values[0] );
				$( "#to_size" ).attr( 'value', ui.values[1] );
				$( "#from_breasts_size_slide_show" ).html(ui.values[0]);
				$( "#to_breasts_size_slide_show" ).html(ui.values[1]);
			},
			stop: function(event, ui) {async_search();return false; }
		});
	/**	
		$( "#slider-size-penis").slider({
			orientation: "horizontal",
			range: "min",
			min: 1,
			max: 30,
			value: SLIDE_PENIS_SIZE,
			slide: function( event, ui ) {
				$( "#penis_size" ).attr( 'value', ui.value );
				$( "#penis_size_slide_show" ).html(ui.value);
			}
		});	**/
		$('#search_result_show_id').html(TOTAL_RESULTS);
		//alert(COND);
	}

	$(document).ready(function(){
		loadDynamicJSResult();
		toggle();

		$('#escort-data').focusout(function(){async_search();return false;});
		//$('input[name=media\\[\\]]').click(function(){async_search();});
		//$('.checkbox-wrapper').live('change',function(){async_search();return false;});
		$('#location_id,#agency_id,#borncountry_id').live('change',function(){async_search();return false;});
		if($.browser.msie){
			$('input[type="checkbox"]').bind('click',function(){ window.setTimeout("async_search()",100);return true;});
		}else{
			$('input:checkbox').live('change',function(){async_search();return false;});
		}	
	});
	
	function async_search(){
		if($('#agentIDCheckedItem').is(':checked') == true){
			$('.wrapAGENT').removeClass('hidden');
			$('#agency_id').height(20);
		}else{
			$('.wrapAGENT').addClass('hidden');
			$('#agency_id').height(0);
		}
		
		$('.search-left .greyDiv').toggle();
		$('#search-escort .search-escort-list').html('');
		$link = BASE_URI+'home/search_page?'+$('#search_form').serialize();
		$.get($link,{},function (res){
			$('#search-escort').html(res);
            scroll(0,0);
			loadDynamicJSResult();
			$('.search-left .greyDiv').toggle();
			return false;
		}); 
		return false;
	}
	
	$(document).ready(function() { 
		$('#search_escort .pagination a').live('click',function(){
			$link = $(this).attr('href');
			$('#greyDiv').show();
			$.get($link,{},function(res){
				$('#greyDiv').hide();
				$('#search-escort').html(res);
                scroll(0,0);
			});
			return false;
		});
		
		$('#search_form').submit(function(){
			$link = BASE_URI+'home/search_page?'+$(this).serialize();
			$('#greyDiv').show();
			$.get($link,{},function (res){
				$('#greyDiv').hide();
				$('#search-escort').html(res);
                scroll(0,0);
				loadDynamicJSResult();
			});
			return false;
		});
		
		$('#country_id').live('change',function(){
			changeCountry_slb($('#country_id').val());
		});
		/**
		$('#state_id').live('change',function(){
			changeState_slb($('#state_id').val(),$('#country_id').val());
		});
		$('#province_id').live('change',function(){
			changeProvince_slb($('#state_id').val(),$('#province_id').val(),$('#country_id').val());
		});
		**/
	});
	
	function changeCountry_slb($country_id){
		$('#slb_state_id, #slb_province_id, #slb_city_id').html('<select class="custome"></select>');
		$('select.custome').customStyle();
		$('#slb_state_id_loader, #slb_province_id_loader, #slb_city_id_loader').show();
		$.post(BASE_URI+'home/changeCountry_async',{country_id:$country_id},function(res){
			$('#slb_state_id_loader').hide();
			$('#slb_state_id').html(res);
			$('#slb_state_id select').customStyle();
		//	$firtElementValue = $('#state_id').children().first().val();
		//	changeState_slb($firtElementValue,$country_id);
		});
	}
/**	
	function changeState_slb($state_id,$country_id){
		$('#slb_province_id, #slb_city_id').html('<select class="custome"></select>');
		$('select.custome').customStyle();
		$('#slb_province_id_loader, #slb_city_id_loader').show();
		$.post(BASE_URI+'registration/changeState_async',{state_id:$state_id,country_id:$country_id},function(res){
			$('#slb_province_id_loader').hide();
			$('#slb_province_id').html(res);
			$('select#province_id').customStyle();
			$firtElementValue = $('#province_id').children().first().val();
			changeProvince_slb($state_id,$firtElementValue,$country_id);
		});
	}
	
	function changeProvince_slb($state_id,$province_id,$country_id){
		$('#slb_city_id').html('<select class="custome"></select>');
		$('select.custome').customStyle();
		$('#slb_city_id_loader').show();
		$.post(BASE_URI+'registration/changeProvince_async',{state_id:$state_id,province_id:$province_id,country_id:$country_id},function(res){
			$('#slb_city_id_loader').hide();
			$('#slb_city_id').html(res);
			$('select#city_id').customStyle();
		});
	}
**/	
</script>

<?php 
	if(isset($_GET['df']) AND $_GET['df'] == 1):
?>
<script type="text/javascript">
	async_search();
</script>
<?php endif;?>	